<template>
  <div class="container">
    <div class="titleTexts">用户收件地址管理</div>
    <el-form ref="ruleForm" :inline="true" :model="searchParams">
      <el-form-item label="搜索" prop="search">
        <el-input
          clearable
          v-model="searchParams.search"
          placeholder="请输入大鹏号/手机号"
        ></el-input>
      </el-form-item>
      <el-form-item class="s-btn">
        <el-button type="success" @click="search">
          查询
        </el-button>
        <el-button type="success" plain @click="reset">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <!--下部table-->
    <el-table
      v-loading="loading"
      :data="tableData"
      stripe
      border
      style="width: 100%"
      max-height="490"
      ref="table"
    >
      <el-table-column type="index" label="序号" width="60"> </el-table-column>
      <el-table-column label="用户名" prop="trueName" min-width="80">
        <template slot-scope="scope">
          {{ scope.row.user.trueName }}
        </template>
      </el-table-column>
      <el-table-column label="大鹏号" prop="dpAccount" min-width="110">
        <template slot-scope="scope">
          {{ scope.row.user.dpAccount }}
        </template>
      </el-table-column>
      <el-table-column label="手机号" prop="mobile" min-width="100">
        <template slot-scope="scope">
          {{ scope.row.user.mobile }}
        </template>
      </el-table-column>
      <el-table-column label="默认收件人" prop="mobile" min-width="100">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="默认联系电话" prop="mobile" min-width="100">
        <template slot-scope="scope">
          {{ scope.row.phone }}
        </template>
      </el-table-column>
      <el-table-column
        label="默认地址"
        prop="address"
        min-width="120"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            `${scope.row.province}${scope.row.city}${scope.row.area}${scope.row.detailedAddress}`
          }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" :width="100">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="showUserAddressListDialog(scope.row.user.userId)"
          >
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-全局组件-->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="getList"
    ></pageCom>
    <user-address-list-dialog
      :userAddressListDialogData="userAddressListDialogData"
    ></user-address-list-dialog>
  </div>
</template>

<script>
import { getAddressList } from '@/api/system/user'
import userAddressListDialog from './userAddressListDialog'

export default {
  components: {
    userAddressListDialog
  },
  data() {
    return {
      loading: false,
      searchParams: {
        search: '',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      userAddressListDialogData: {
        isShow: false
      }
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      getAddressList(
        this.searchParams,
        (res) => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
        },
        (res) => {
          this.loading = false
          this.$message({
            message: res.message,
            type: 'warning'
          })
        }
      )
    },
    search() {
      this.searchParams.pageNum = 1
      this.getList()
    },
    reset() {
      this.searchParams.search = ''
    },
    showUserAddressListDialog(userId) {
      this.userAddressListDialogData.userId = userId
      this.userAddressListDialogData.isShow = true
    }
  }
}
</script>

<style scoped lang="less">
.container {
  padding: 15px;
}
:deep(.el-input__inner) {
  height: 35px;
}
.titleTexts {
  font-size: 20px;
  margin-bottom: 10px;
}
</style>
